package ModelLayer;
import java.util.ArrayList;

/**
 * Write a description of class LoginContainer here.
 * 
 * @author Group1 
 * @version 2011-06-08
 */
public class LoginContainer
{
    private ArrayList<Login> logins;
    private static LoginContainer _instance = null;
    
    /**
     * Creates an ArrayList.(Container for Login)
     */
    private LoginContainer()
    {
        logins = new ArrayList<Login>();
    }
    
    /**
     * Creates an instance of LoginContainer
     * @return Returns an instance of LoginContainer
     */
    public static LoginContainer getInstance()
    {
        if(null == _instance)
        {
            _instance = new LoginContainer();
        }
        return _instance;
    }
    
    /**
     * create a login to LoginContainer
     * @param take a parameter of type Login
     */    
    public void createLogin(Login newLogin)
    {
        logins.add(newLogin);
    }

    /**
     * Find a login from the LoginContainer
     * @param searchName SearchName of the person
     * @param searchPassword SearchPassword of the person
     */    
    public boolean searchForLogin(String searchName, String searchPassword)
    {
        boolean found = false;
        int index = 0;
        while(index < logins.size() && !found)
        {
            if(logins.get(index).getLoginName().equals(searchName) && logins.get(index).getPassword().equals(searchPassword))
            {
                found = true;
            }
            index++;
        }
        return found;
    }

    /**
     * Find a loginName from the LoginContainer
     * @param searchName SearchName of the person
     */
    public Login searchForLoginName(String searchName)
    {
        boolean found = false;
        int index = 0;
        Login login = null;
        while(index < logins.size() && !found)
        {
            if(logins.get(index).getLoginName().equals(searchName))
            {
                found = true;
                login = logins.get(index);
            }
            index++;
        }
        return login;
    }

    /**
     * Delete login from the LoginContainer
     * @param take an objekt of the type login
     */    
    public void deleteLogin(String searchLoginName)
    {
        Login login = searchForLoginName(searchLoginName);
        logins.remove(login);
    }
}